class LogReport {
  listen(title, elementTypeEventArray) {
    for (let i = 0; i < elementTypeEventArray.length; i += 3) {
      let element = elementTypeEventArray[i]
      const type = elementTypeEventArray[i + 1],
        event = elementTypeEventArray[i + 2]
      if (element.$el) {
        element = element.$el
      }
      if (element instanceof HTMLElement) {
        element.addEventListener('click', () => {
          this.event(title, type, event)
        })
      } else {
        log.warn(`${typeof element} is not a HTMLElement`)
      }
    }
  }
  removeListen() {}
  pv(options) {
    return this.send({
      behaviour_type: 'pv',
      ...options
    })
  }

  event(title, behaviourType, behaviourEvent, url) {
    return this.send({
      title,
      url,
      behaviour_type: behaviourType,
      behaviour_event: behaviourEvent
    })
  }

  send(options) {
    if (!options.url) {
      var reg = new RegExp('&', 'g')
      var newUrl = window.location.href.replace(reg, '|')
      options.url = newUrl
      options.url = window.location.href
    }
    if (!options.title) {
      options.title = document.title
    }
    //return api.recordPoint.adminLog.addPoint({ data: options });
  }
}

export default new LogReport()
